package com.niknik.woody.core.room;

import com.google.inject.Inject;
import com.google.inject.Provider;
import com.niknik.woody.core.IdFactory;

import java.util.Collection;
import java.util.Map;

public class RoomRegistry {

  @Inject private Map<String, Room> rooms;
  @Inject private Provider<Room> roomFactory;
  @Inject private IdFactory idFactory;

  public Room create() {
    String roomId = idFactory.takeId();
    Room room = roomFactory.get();
    room.init(roomId);

    this.rooms.put(roomId, room);
    return room;
  }

  public Collection<Room> getRoomsSnapshot() {
    return this.rooms.values();
  }

  public Room get(String roomId) {
    return this.rooms.get(roomId);
  }

  public Room delete(String roomId) {
    return rooms.remove(roomId);
  }
}
